package com.api.shopapi.mapper;

import com.api.shopapi.entity.CheckinAssessItem;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author maochuan
 */
@Repository
@Mapper
public interface CheckinAssessItemMapper {
    @Insert("insert into checkin_assess_item " +
            "(CheckinAssessItemCode,Name,CheckinAssessGroupCode,Fraction) " +
            "value(#{checkinAssessItem.CheckinAssessItemCode},#{checkinAssessItem.Name},#{checkinAssessItem.CheckinAssessGroupCode}," +
            "#{checkinAssessItem.Fraction})")
    int insert(@Param("checkinAssessItem") CheckinAssessItem checkinAssessItem);

    @Delete("delete from checkin_assess_item where checkinAssessItemCode=#{checkinAssessItemCode}")
    int deleteByCheckinAssessItemCode(@Param("checkinAssessItemCode") String checkinAssessItemCode);

    @Update("update checkin_assess_item set Name = #{checkinAssessItem.Name}," +
            "Sort=#{checkinAssessItem.CheckinAssessGroupCode},Status=#{checkinAssessItem.Fraction} " +
            "where CheckinAssessItemCode=#{checkinAssessItem.CheckinAssessItemCode}")
    int updateByCheckinAssessItemCode(@Param("checkinAssessItem") CheckinAssessItem checkinAssessItem);

    @Select("select * from checkin_assess_item")
    List<CheckinAssessItem> getListAll();

    @Select("select * from checkin_assess_item where CheckinAssessItemCode=#{checkinAssessItemCode} limit 1")
    CheckinAssessItem getByCheckinAssessItemCode(@Param("checkinAssessItemCode") String checkinAssessItemCode);

    @Select("select * from checkin_assess_item where CheckinAssessGroupCode=#{checkinAssessGroupCode} and Name=#{name} limit 1")
    CheckinAssessItem getByCheckinAssessGroupCodeAndName(@Param("checkinAssessGroupCode") String checkinAssessGroupCode, @Param("name")String name);

    @Select("select * from checkin_assess_item where CheckinAssessGroupCode=#{checkinAssessGroupCode} order by Fraction asc")
    List<CheckinAssessItem> getByCheckinAssessGroupCode(@Param("checkinAssessGroupCode") String checkinAssessGroupCode);

    @Delete("delete from checkin_assess_item where CheckinAssessGroupCode=#{checkinAssessGroupCode}")
    int deleteByCheckinAssessGroupCode(@Param("checkinAssessGroupCode") String checkinAssessGroupCode);
}
